# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgbase=lua-yaml
_rockname=${pkgbase#lua-}
pkgname=("$pkgbase" "lua51-$_rockname" "lua52-$_rockname" "lua53-$_rockname")
pkgver=1.1.2
_rockrel=1
pkgrel=7
pkgdesc='LibYAML binding for Lua'
arch=(loong64 x86_64 i686)
url="https://lubyk.github.io/lubyk/$_rockname.html"
license=(MIT)
_luadeps=(lub)
makedepends=(lua
             lua51
             lua52
             lua53
             luarocks)
checkdepends=("${_luadeps[@]/#/lua-}"
              lua-lut)
options=(debug)
_archive="$_rockname-REL-$pkgver"
_rock="${_archive/-REL}-$_rockrel.linux-$CARCH.rock"
_rockspec="${_archive/-REL}-$_rockrel.rockspec"
source=("https://github.com/lubyk/$_rockname/archive/REL-$pkgver/$_archive.tar.gz")
sha256sums=('b4391d182677ab644403bf1ac028c7421c2605db124f9792193013c582a273ec')

check() {
	cd "$_archive"
	lua test/all.lua
}

build() {
	cd "$_archive"
	for LUAVER in 5.{1,2,3,4}; do
		luarocks --lua-version "$LUAVER" \
			make --pack-binary-rock --deps-mode none -- "$_rockspec"
		install -Dm0644 -t "lua-$LUAVER/" "$_rock"
	done
}

_package() {
	cd "$_archive"
	depends=("${pkgname%-*}" "${_luadeps[@]/#/${pkgname%-*}-}")
	luarocks --lua-version "$1" --tree "$pkgdir/usr/" \
		install --deps-mode none --no-manifest -- "lua-$1/$_rock"
	install -Dm0644 -t "$pkgdir/usr/share/licenses/$pkgname/" LICENSE
}

package_lua-yaml() {
	_package 5.4
}

package_lua53-yaml() {
	_package 5.3
}

package_lua52-yaml() {
	_package 5.2
}

package_lua51-yaml() {
	_package 5.1
}
